package com.dk.auth.web.api;

import com.dk.auth.web.model.login.UserVO;
import com.dk.common.defs.CommonDefs;
import com.dk.common.result.ApiResult;
import com.dk.auth.core.service.LoginService;
import com.dk.common.model.UserDTO;
import com.dk.auth.web.model.login.LoginVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "auth接口")
@Slf4j
@RestController
@RequestMapping(CommonDefs.RESTFUL_URI_CONTEXT+"/auth")
public class AuthApi {

    @Autowired
    private LoginService loginService;

    @Operation(summary = "登录")
    @PostMapping("/login")
    public ApiResult<UserVO> login(@RequestBody LoginVO loginVO) {
        UserDTO userDTO = loginService.login(loginVO.getUserName(), loginVO.getPassword());
        return ApiResult.success(UserVO.builder()
                .userName(userDTO.getUserName())
                .nickName(userDTO.getNickName())
                .token(userDTO.getToken())
                .build());
    }

}
